package com.lb.uts.service.policy;


import com.lb.uts.constants.LogConstants;
import com.lb.uts.entity.CacheClient;
import com.lb.uts.entity.ScheduleJob;
import com.lb.uts.util.PolicyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 返回全部的执行器
 *
 * @author liangb
 * @version 3.0
 * @date 2019/4/28 11:58
 */
@Service
public class BatchSchedulingPolicy implements ISchedulingPolicy<CacheClient> {

    private static final Logger logger = LoggerFactory.getLogger(BatchSchedulingPolicy.class);

    @Override
    public List<CacheClient> getSuitActiveClients(ScheduleJob job) {
        String systemName = job.getSystemName();
        while (true) {
            if (!PolicyUtil.JOB_IP_LIST_CHANGING) {
                List<CacheClient> jobIps = PolicyUtil.JOB_IP_LIST.get(systemName);
                return jobIps;
            } else {
                //此时后台线程正在刷新内存，等待，继续尝试
                logger.info(LogConstants.RANDOM_SCHEDULING_POLICY + "后台线程正在更新ip list，等待");
            }
        }
    }

}
